import React from 'react'
import { NavBar } from 'antd-mobile'
import { useHistory } from 'react-router-dom'
import styles from './index.module.scss'
import PropTypes from 'prop-types'
function NavHeader({ children, onLeftClick }) {
  const history = useHistory()
  // 默认左侧点击
  const defaultHandler = () => {
    history.go(-1)
  }
  return (
    <NavBar
      className={styles.navbar}
      mode="light"
      icon={<i className="iconfont icon-back" />}
      onLeftClick={onLeftClick || defaultHandler}
    >
      {children}
    </NavBar>
  )
}

NavHeader.propTypes = {
  children: PropTypes.string.isRequired,
  onLeftClick: PropTypes.func
}
export default NavHeader
